/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upc.spring.jmspro;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.jms.support.JmsUtils;

/* @author DBA Carlo*/
 
public class jmsService {    
    private JmsTemplate jmsTemplate;

    public jmsService(JmsTemplate template) {
       this.jmsTemplate = template;
    }
  
  public void sendMessage() {    
      
   jmsTemplate.send(new MessageCreator() {  
          public Message createMessage(Session session) 
              throws JMSException {  
              return session.createTextMessage("Hello");
            }  
      });   
   }

 public String receiveMessage() {
       try {
        TextMessage receivedMessage = (TextMessage) jmsTemplate.receive();
          return (String) receivedMessage.getText();        } 
        
        catch (JMSException jmsException) {  
      throw JmsUtils.convertJmsAccessException(jmsException);
        }
   }
 
 
}
